//
//  WeiboListViewController.m
//  WeiboAD
//
//  Created by liu guoqiang on 16/7/19.
//  Copyright © 2016年 com.liu.weiboAD. All rights reserved.
//

#import "WeiboListViewController.h"
#import "WeiboTableViewCell.h"
#import "ReactiveCocoa.h"

@interface WeiboListViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *WeiboTabelView;
@property (nonatomic,strong)WeiboListViewModel *viewModel;
@end

@implementation WeiboListViewController

-(instancetype)init
{
    self = [super init];
    if (self) {
      
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的微博";
    self.WeiboTabelView.delegate = self;
    self.WeiboTabelView.dataSource = self;
    [self.WeiboTabelView registerNib:[UINib nibWithNibName:@"WeiboTableViewCell" bundle:nil] forCellReuseIdentifier:@"WeiboTableViewCell"];
    
    _viewModel = [[WeiboListViewModel alloc]init];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[@"access_token"] = [UserDefault getValueOfKey:@"access_token"];
    dic[@"uid"] = [UserDefault getValueOfKey:@"uid"];
     __weak typeof(self) wself = self;
    _viewModel.refreshblock = ^(void){
        [wself.WeiboTabelView reloadData];
         NSLog(@"viewmodel:%@",wself.viewModel.weiboArray);
    };
    [_viewModel getWeibo:dic];
   

    // Do any additional setup after loading the view from its nib.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _viewModel.weiboArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    WeiboTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WeiboTableViewCell" forIndexPath:indexPath];
    cell.weibo = _viewModel.weiboArray[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 300;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
